package cn.ghx.xboot.order.demand;

import cn.ghx.xboot.common.BaseContext;
import cn.ghx.xboot.front.vo.OrderDemandVo;
import com.baomidou.mybatisplus.extension.conditions.query.LambdaQueryChainWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import cn.ghx.xboot.mapper.OrderDemandMapper;
import org.springframework.stereotype.Service;
import org.springframework.util.Assert;
import org.springframework.util.StringUtils;

/**
* @author ghx
* @description 针对表【t_order_demand(帮我找机订单)】的数据库操作Service实现
* @createDate 2024-04-16 18:04:47
*/
@Service
public class OrderDemandService extends ServiceImpl<OrderDemandMapper, OrderDemand> {

    public Boolean saveVo(OrderDemandVo vo) {
        String openid = BaseContext.getOpenid();
        Assert.isTrue(StringUtils.hasText(openid) , "请登录");
        OrderDemand it = vo.toEntity();
        it.setOpenid(openid);
        return save(it);
    }

    public OrderDemand findById(String id) {
        return getById(id);
    }

    public Boolean deleteById(String id) {
        return removeById(id);
    }

    public Boolean saveItem(OrderDemand item) {
        return saveOrUpdate(item);
    }

    public Page<OrderDemand> query(String keyword,
                                   String province,
                                   String city,
                                   String district,
                                   String openid,
                                   String storeId,
                                   Integer page, Integer size) {
        LambdaQueryChainWrapper<OrderDemand> qw = lambdaQuery();
        // 参数
        if (StringUtils.hasText(keyword)) {
            qw.and(w -> {
                w.like(OrderDemand::getBrand, keyword).or()
                        .like(OrderDemand::getRemark, keyword);
            });
        }
        if(StringUtils.hasText(province)){
            qw.eq(OrderDemand::getProvince,province);
        }
        if(StringUtils.hasText(city)){
            qw.eq(OrderDemand::getCity,city);
        }
        if(StringUtils.hasText(district)){
            qw.eq(OrderDemand::getDistrict,district);
        }
        if(StringUtils.hasText(openid)){
            qw.eq(OrderDemand::getOpenid,openid);
        }
        if(StringUtils.hasText(storeId)){
            qw.eq(OrderDemand::getStoreId,storeId);
        }

        return qw.page(Page.of(page, size));
    }
}




